package com.mebs.model;

import javax.persistence.Entity;

import org.jt.jet.content.JetNamedObject;

@Entity()
public enum WeightUnit implements JetNamedObject {
    LBS(1, "Pounds", "lbs", 'L', 453.59),
    KGS(2, "Kilograms", "kgs", 'K', 1000.0),
    CWT(3, "Hundredweight", "cwt", 'C', 45300.0);

    public final int type;
    public final String name;
    public final String shortName;
    public final Character veryShortName;
    public final Double coef; // to 1 gram

    WeightUnit(int type, String name, String shortName, Character veryShortName, Double coef)
    {
        this.type = type;
        this.name = name;
        this.shortName = shortName;
        this.veryShortName = veryShortName;
        this.coef = coef;
    }

    public static WeightUnit getObjectByType(int type) {
        return WeightUnit.values()[type - 1];
    }
    
    public static int getTypeByAbbreviation(String abbreviation) {
    	if ("L".equalsIgnoreCase(abbreviation)) {
    		return 1; // pounds
    	} else if ("K".equalsIgnoreCase(abbreviation)) {
    		return 2; // kilograms
    	} else {
    		throw new IllegalArgumentException("Unknown weight unit abbreviation: " + abbreviation);
    	}
    }

    public Object getObjectId()
    {
        return type;
    }

    public String getObjectName()
    {
        return name;
    }

    public int getType()
    {
        return type;
    }

    public String getName()
    {
        return name;
    }
    
    public String getShortName()
    {
        return shortName;
    }
    
    public Character getVeryShortName()
    {
        return veryShortName;
    }

    public Double getCoef()
    {
        return coef;
    }
}
